<?php
    session_start();  
    require 'crud/CustomSecurity.class.php';
    require 'common/Utility.php';
    require 'crud/Userdata.class.php';
    require 'crud/Prognosis.class.php';
    require 'crud/Matches.class.php';
    require 'db/configuration.php';
    loginCheck();
    loadDB();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="bg">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    <link rel="stylesheet" type="text/css" href="css/page.css" />
    <link rel="stylesheet" type="text/css" href="css/main.css" />
    <link rel="stylesheet" type="text/css" href="css/generalProduct.css" />
    <link rel="stylesheet" type="text/css" href="css/add-product.css" />
    <link rel="stylesheet" href="js/autocomplete/jquery.autocomplete.css" type="text/css" />

    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
  	<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
	<title>Добави продукт</title>
	<meta name="author" content="Dimtiar Giormov">
	
</head>
    <body>
    <?php 
		if (isset($_POST['idm'])){
			$crud = new Prognosis(con());
			$line = $crud->get($_POST['idm']);
			if (count($line) == 0){
				$crud->add($_POST['idm'], $_POST['resA'], $_POST['resB']);
				echo "<script language=javascript> window.top.location.reload(1); </script>";
			} else {
				$crud->update($_POST['idm'], $_POST['resA'], $_POST['resB']);
				echo "<script language=javascript> window.top.location.reload(1); </script>";
			}
			
		} 
	?>
        	<div id="add-product">
			<form action="matchpredictions.php" name="addproduct" method="post" autocomplete="off">
    			<div id="add-product-left">
    				<ol>
    				<?php
    				if(isset($_GET['idm'])){
    					$matches = new Matches(con());
    					$match = $matches->getObject($_GET['idm']);
    					echo "<li>".$match[0][1]."</li>";
    					echo "<li>".$match[0][2]."</li>";
    				}
    					
    				?>
    				
    					<li><input class="table-submit" type="submit" value="Save"></li>
    				</ol>
    			</div>  
    			<div id="add-product-right">
    				<ol>
    					<li>    					
    				<input class="table-input" type="text" id="testinput" name="resA">
    					</li>
    					<li>
    					<input class="table-input" type="text" id="testinput1" name="resB">
    					<?php
    					echo '<input type="hidden" id="idm" name="idm" value='.$_GET['idm'].'>'; 
    					?>
    					
    					</li>
					</ol>
				</div>
			</form>
		</div>
	
	 <script>
  $(document).ready(function(){
	  $("#testinput").autocomplete('test2.php');
		 setTimeout("$(\"input[name='brand']\").focus();", 100);
	
  });
  </script>
    </body>
</html>